package main.java.controlMediator;

import java.util.ArrayList;
import java.util.List;

import main.java.aircraft.Aircraft;

public class RegionalAirTrafficControlConcreteMediator implements AirTrafficControlBaseMediator
{
	 /**
	 * @uml.property  name="registeredAircrafts"
	 * @uml.associationEnd  multiplicity="(0 -1)" elementType="main.java.aircraft.Aircraft"
	 */
	private List<Aircraft> registeredAircrafts = new ArrayList<Aircraft>();

	public void RegistrerAircraft(Aircraft aircraft) {
		
		 if (!registeredAircrafts.contains(aircraft))
	        {
	            registeredAircrafts.add(aircraft);
	        }	
	}

	public void SendWarningMessage(Aircraft aircraft) {
		for (Aircraft regAcrft : registeredAircrafts) {
			if (!regAcrft.equals(aircraft) &&
					 Math.abs(regAcrft.getAltitude() - aircraft.getAltitude()) < 500) {
				regAcrft.ReceiveWarning(aircraft);
		        aircraft.increaseAltitude(1000);
			}
		}		
	}
}
